home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / PC_LIBS / C045.ZIP / BTREE.ARC / BTUTIL.C < prev    next >
C/C++ Source or Header  |  1989-02-05  |  6KB  |  206 lines

  1. #include <bios.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <dos.h>
  5. #include <conio.h>
  6. #include <ctype.h>
  7. #include "cstruct.h"
  8. #include "ctrlkey.h"
  9. #include "globals.h"
  10.  
  11. static int  KbdRead;
  12.  
  13. char * conststr(int ch, int n)
  14. {
  15.     memset(buffer, ch, n);
  16.     buffer[n] = '\0';
  17.     return (buffer);
  18. }
  19.  
  20. void gotoxy(int column, int row)
  21. {
  22.     inregs.h.ah = 2;
  23.     inregs.h.bh = 0;
  24.     inregs.h.dh = row - 1;
  25.     inregs.h.dl = column - 1;
  26.  
  27.     int86(0x10, &inregs, &outregs);
  28. }
  29.  
  30. void clearwindow(int ux, int uy, int lx, int ly)
  31. {
  32.     inregs.x.ax = 0x0600;           /* fcn 6, al = 0 implies blank window */
  33.     inregs.h.bh = 0x07;             /* normal attribute */
  34.     inregs.h.cl = ux - 1;           /* for upper left window column */
  35.     inregs.h.ch = uy - 1;           /* for upper left window row */
  36.     inregs.h.dl = lx - 1;           /* for lower right window column */
  37.     inregs.h.dh = ly - 1;           /* for lower right window row */
  38.  
  39.     int86(0x10, &inregs, &outregs);
  40. }
  41.  
  42. void beep(void)
  43. {
  44.     int i;
  45.  
  46.     for (i = 1; i <= 2; i++) {
  47.       sound(784);     delay(70);  nosound();
  48.       sound(587);     delay(70);  nosound();
  49.     }
  50. }
  51.  
  52. int select(char * prompt, char * charset)
  53. {
  54.     char   ch;
  55.  
  56.     gotoxy(1, 23);  printf("%s", prompt);  clreol();
  57.  
  58.     if (strlen(charset) == 0)
  59.         return (NULL);
  60.  
  61.     ch = getch();
  62.     while (strchr(charset, ch) == NULL) {
  63.         beep();
  64.         ch = getch();
  65.     }
  66.  
  67.     return (ch);
  68. }
  69.  
  70. int getkey(void)
  71. /* Uses the BIOS to read the next keyboard character */
  72. {
  73.     int key, lo, hi;
  74.  
  75.     key = bioskey(KbdRead);
  76.     lo = key & 0x00ff;
  77.     hi = (key & 0xff00) >> 8;
  78.  
  79.     if (lo == 0 || lo == 0xe0)
  80.         return (hi + 0x100);
  81.     else
  82.         return (lo);
  83. } /* getkey */
  84.  
  85. char inputstr(char * chp, int lngth, int x, int y, char * chrset)
  86. {
  87.     unsigned    i, p, custlen, ch;
  88.  
  89.     gotoxy(x, y);
  90.     chp[lngth] = '\0';
  91.     printf("%s%s", chp, conststr('_', lngth - strlen(chp)));
  92.     p = 0;
  93.     do {
  94.         gotoxy(x+p, y);
  95.         ch = getkey();
  96.         if (isprint(ch)) {
  97.             for (i = lngth-1; i >= p+1; i--)
  98.                 chp[i] = chp[i-1];
  99.             chp[p] = ch;
  100.             printf("%s", &chp[p]);
  101.             if (p < lngth-1) p++;
  102.         }
  103.         else switch (ch) {
  104.             case RIGHT:
  105.             case CTLD : if (p < strlen(chp)-1) p++;
  106.                         else beep(); break;
  107.             case LEFT :
  108.             case CTLS : if (p > 0) p--;
  109.                         else beep(); break;
  110.             case CTLLFT:
  111.             case CTLA : p = 0; break;
  112.             case CTLRGT:
  113.             case CTLF : if ((custlen = strlen(chp)) < lngth)
  114.                             p = custlen;
  115.                         else
  116.                             p = custlen-1;
  117.                         break;
  118.             case DELETE :
  119.             case CTLG : custlen = strlen(chp);
  120.                         for (i = p; i <= custlen-1; i++)
  121.                             chp[i] = chp[i+1];
  122.                         printf("%s_", &chp[p]);
  123.                         break;
  124.             case CTLH : if (p > 0) {
  125.                             custlen = strlen(chp);
  126.                             for (i = p-1; i <= custlen-1; i++)
  127.                                 chp[i] = chp[i+1];
  128.                             printf("%c%s_", '\x08', &chp[p-1]);
  129.                             p--;
  130.                         }
  131.                         break;
  132.             case CTLDEL :
  133.             case CTLY : printf("%s", conststr('_', strlen(chp)-p));
  134.                         chp[p] = '\0';
  135.                         break;
  136.             default :   break;
  137.         }
  138.     } while (!strchr(chrset, ch));
  139.  
  140.     clearwindow (x + strlen(chp), y, x + lngth - 1, y);
  141.  
  142.     return (ch);
  143. }
  144.  
  145. void outform(void)
  146. {
  147.     gotoxy( 1,  5); printf("%12s", "Code :");
  148.     gotoxy(30,  5); printf("Date :");
  149.     gotoxy( 1,  7); printf("%12s", "First name :");
  150.     gotoxy(30,  7); printf("Last name :");
  151.     gotoxy( 1,  9); printf("%12s", "Company :");
  152.     gotoxy( 1, 10); printf("%12s", "Address 1 :");
  153.     gotoxy( 1, 11); printf("%12s", "Address 2 :");
  154.     gotoxy( 1, 13); printf("%12s", "Phone :");
  155.     gotoxy(30, 13); printf("Extension :");
  156.     gotoxy( 1, 15); printf("%12s", "Remarks 1 :");
  157.     gotoxy( 1, 16); printf("%12s", "Remarks 2 :");
  158.     gotoxy( 1, 17); printf("%12s", "Remarks 3 :");
  159. }
  160.  
  161. void clearform(void)
  162. {
  163.     clearwindow (14, 5, 28, 5);
  164.     clearwindow (37, 5, 80, 5);
  165.     clearwindow (14, 7, 28, 7);
  166.     clearwindow (42, 7, 80, 7);
  167.     clearwindow (14, 9, 80, 9);
  168.     clearwindow (14,10, 80,10);
  169.     clearwindow (14,11, 80,11);
  170.     clearwindow (14,13, 28,13);
  171.     clearwindow (42,13, 80,13);
  172.     clearwindow (14,15, 80,15);
  173.     clearwindow (14,16, 80,16);
  174.     clearwindow (14,17, 80,17);
  175. }
  176.  
  177. void initkeyboard()
  178. {
  179.     KbdRead = get_kbd() ? 0x10 : 0x00;
  180. }
  181.  
  182. static int get_kbd()
  183. {
  184.     char    saved;
  185.     int     status;
  186.     int     chk_kbd_bios();
  187.  
  188.     if ((status = chk_kbd_bios()) != 0) { /* if system rom support the  */
  189.         saved = peekb(0, 0x417);        /* enhanced keyboard, it must   */
  190.         pokeb(0, 0x417, 0x70);          /* pass status check test twice.*/
  191.         status = chk_kbd_bios();
  192.         pokeb(0, 0x417, saved);
  193.     }
  194.     return (status);
  195. }
  196.  
  197. static int chk_kbd_bios()
  198. {
  199.     union REGS regs;
  200.  
  201.     regs.x.ax = 0x1200;
  202.     int86 (0x16, ®s, ®s);
  203.  
  204.     return ( (regs.h.al == peekb(0, 0x417)) ? 1 : 0 );
  205. }
  206.